package com.qs.springboot.util;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * 配置kafka的consumer
 *
 * @author qinyupeng
 * @since 2019-12-18 14:39:03
 */
@Component
public class KafkaConsumer {

    /**
     * consumer监听topic=myTopic，等待从topic中获取到producer发送的数据
     */
    @KafkaListener(topics = {"myTopic"})
    public void listen(ConsumerRecord consumerRecord) {
        String topic = consumerRecord.topic();
        Object key = consumerRecord.key();
        Object value = consumerRecord.value();
        long offset = consumerRecord.offset();

        System.out.println("topic=" + topic);
        System.out.println("key=" + key);
        System.out.println("value=" + value);
        System.out.println("offset=" + offset);
    }
}
